local function ParseFind(inStr, fName)
local inStr = file.Read(fName)
inStr = string.Explode(inStr, "\n")
	for i = 1, #inStr do
		if string.find(inStr[i], "\[") then
			CurCat = string.gsub(inStr[i], "\\[", "")
			CurCat = string.gsub(inStr[i], "\]", "")
			if string.lower(CurCat) == string.lower(inStr) then
				if string.find(inStr[i], "=") then
					local apos = string.find(inStr[i], "=")
						apos = apos - 1
					local Setting = string.Left(inStr, apos)
					local bpos = string.find(string.reverse(inStr), "=")
						bpos = bpos - 1
					local Value = string.Right(inStr, bpos)
					AMax[CurCat] = {}
					AMax[CurCat][Setting] = Value
				elseif string.find(inStr[i], "\[") then
					return true
				end
			end
		end
	end
end

local function ParseFile(fName)
local inStr = file.Read(fName);
inStr = string.Explode(inStr, "\n")
	for i = 1, #inStr do
		local CurCat = string.find(inStr[i], "\[")
		if CurCat then
			CurCat = string.gsub(inStr[i], "\[", "")
			CurCat = string.gsub(inStr[i], "\]", "")
		elseif string.find(inStr[i], "=") then
			local apos = string.find(inStr[i], "=")
				apos = apos - 1
			local Setting = string.Left(inStr, apos)
			local bpos = string.find(string.reverse(inStr), "=")
				bpos = bpos - 1
			local Value = string.Right(inStr, bpos)
		end
		AMax[CurCat] = {}
		AMax[CurCat][Setting] = Value
	end
end

function ParseConfiguration(Type, fName, inStr)
local ErrorSrc = {}
Type = string.upper(Type)
	if Type == "FILE" then
		ParseFile(fName)
	elseif Type == "FIND" then
		if fName then
			ParseFind(inStr, fName)
		else
			ErrorSrc.Str = "No filename given, loading default config file."
			AMax:SendError(ErrorSrc, true)
			if file.Exists("AdminMax/Config.txt") then
				ParseFind(inStr, "AdminMax/Config.txt")
			else
				ErrorSrc.Type = "Default config file not found"
				ErrorSrc.File = "Config Parser"
			end
		end
	else
		ErrorSrc.Type = "Invalid type"
		ErrorSrc.File = "Config Parser"
		AMax:SendError(ErrorSrc)
	end
end